package cn.itcast.controller;

import cn.itcast.entity.Result;
import cn.itcast.pojo.Member;
import cn.itcast.service.MemberService;
import cn.itcast.utils.ThreadLocalUtils;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Reference
    private MemberService memberService;

    /**
     * 校验登录
     * 请求方式 : Post
     * 请求路径 : /member/login
     * 请求参数 : phone : 手机号
     *           validateCode : 验证码
     * 返回值: token
     */
    @PostMapping("/login")
    public Result memberLogin(@RequestBody Map map){
        String phone = (String) map.get("phone");
        //调用service,完成校验登录
        Result result = memberService.memberLogin(map);
        //Member member = memberService.findByPhone(phone);
        //ThreadLocalUtils.setUser(member);
        //Integer id = ThreadLocalUtils.getUser().getId();
        return result;
    }
}
